package com.zryc.shop.ums.mapper;

import com.zryc.shop.ums.entity.Resource;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 后台资源表 Mapper 接口
 * </p>
 *
 * @author LiYe
 * @since 2023-02-02
 */
@Repository
public interface ResourceMapper extends BaseMapper<Resource> {
    @Select("SELECT * FROM ums_resource WHERE id IN (SELECT resource_id FROM ums_role_resource_relation WHERE role_id = #{param1})")
    List<Resource> selectListByRoleId(Long roleId);

    @Delete("DELETE FROM ums_role_resource_relation WHERE role_id = #{param1}")
    int deleteRoleResourceRelation(Long roleId);

    @Insert("INSERT INTO ums_role_resource_relation VALUE(NULL, #{param1}, #{param2})")
    int insertRoleResourceRelation(Long roleId, Long resourceId);
}
